﻿//***************************************************************************//
//                                                                           //
//Author:       Kris Henry                                                   //
//Class Name:   MainMenuState.cs                                             //
//Pupose:       Hadle the drawing and input for the main menu                //
//Date :        December 2012                                                //
//                                                                           //
//***************************************************************************//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.IO;
namespace Indie_Game_Contest
{
    class MainMenuSate:  IGameState
    {
        int MenuFont;
        int option;
        KeyboardState keys;
        private KeyboardState prevkeys;
        GamePadState stick ,prevstick; 
       
        public int MenuFont1
        {
            get { return MenuFont; }
            set { MenuFont = value; }
        }
        int background;

        public int Background
        {
            get { return background; }
            set { background = value; }
        }
        private static MainMenuSate instance;
        public static MainMenuSate Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new MainMenuSate();
                }
                return instance;
            }
        }

         private MainMenuSate()
        {

        }
        override public void Update(float dt)
        {
            

        }
        override public bool Input()
        {
            AudioManager aManager = AudioManager.Instance;

            stick = GamePad.GetState(PlayerIndex.One);
            
            keys = Keyboard.GetState();
            if (CInput.Instance.KeyPressed(Keys.Down) || (CInput.Instance.KeyPressed(Keys.S))  || stick.DPad.Down == ButtonState.Pressed && prevstick.DPad.Down == ButtonState.Released)
            {
                aManager.PlaySFX("Menu_Move");
                option++;
                if (option > 4)
                    option = 0;

            }
            if (CInput.Instance.KeyPressed(Keys.Up) || (CInput.Instance.KeyPressed(Keys.W))  || stick.DPad.Up == ButtonState.Pressed && prevstick.DPad.Up == ButtonState.Released)
            {
                option--;
                if (option < 0)
                    option = 4;
                aManager.PlaySFX("Menu_Move");

            }

            if (option == 4 && CInput.Instance.KeyPressed(Keys.Enter) || option == 4 && CInput.Instance.GamePadButtonPressed(Buttons.A))
            {
                Game1.Instance.ExitGame = true;

            }
            if (option == 3 && CInput.Instance.KeyPressed(Keys.Enter) || option == 3 && CInput.Instance.GamePadButtonPressed(Buttons.A))
            {
                Game1.Instance.AddState(Credits.Instance);
            }
            if (option == 2 && CInput.Instance.KeyPressed(Keys.Enter) || option == 2 && CInput.Instance.GamePadButtonPressed(Buttons.A))
            {
                //Game1.Instance.RemoveState(this);
                Game1.Instance.AddState(OptionsState.Instance);

                aManager.PlaySFX("Menu_Enter");

                Game1.Instance.RemoveState(this);
            }
            if (option == 1 && CInput.Instance.KeyPressed(Keys.Enter) || option == 2 && CInput.Instance.GamePadButtonPressed(Buttons.A))
            {
                Game1.Instance.AddState(InstructionState.Instance);
                Game1.Instance.RemoveState(this);

            }


            if (option == 0 && CInput.Instance.KeyPressed(Keys.Enter) || option == 0 && CInput.Instance.GamePadButtonPressed(Buttons.A))
            {

                //Game1.Instance.AddState(GameplayState.Instance);
                aManager.PlaySFX("Menu_Enter");

                Game1.Instance.AddState(GameControlState.Instance);

                Game1.Instance.RemoveState(this);
            }
            prevkeys = keys;
            prevstick = stick;
            return true;
        }
        override public void Render()
        {
            //WorldData.spriteBatch.Draw(

            WorldData.spriteBatch.Draw(TextureManager.Instance.GetTexture(CTileManager.Instance.TileIDs["curtains"]),
                new Rectangle(0, 0, WorldData.WindowWidth, WorldData.WindowHeight), Color.White);
            
            int nX = (WorldData.WindowWidth / 2) - 60;
            if (option == 0)
                WorldData.spriteBatch.DrawString(TextureManager.Instance.GetSpriteFont(MenuFont1), "Play", new Vector2(nX, 100), Color.Yellow);
            else
                WorldData.spriteBatch.DrawString(TextureManager.Instance.GetSpriteFont(MenuFont1), "Play", new Vector2(nX, 100), Color.White);

            if (option == 1)
                WorldData.spriteBatch.DrawString(TextureManager.Instance.GetSpriteFont(MenuFont1), "Instructions", new Vector2(nX, 150), Color.Yellow);
            else
                WorldData.spriteBatch.DrawString(TextureManager.Instance.GetSpriteFont(MenuFont1), "Instructions", new Vector2(nX, 150), Color.White);

            if (option == 2)
                WorldData.spriteBatch.DrawString(TextureManager.Instance.GetSpriteFont(MenuFont1), "Options", new Vector2(nX, 200), Color.Yellow);
            else
                WorldData.spriteBatch.DrawString(TextureManager.Instance.GetSpriteFont(MenuFont1), "Options", new Vector2(nX, 200), Color.White);

            if (option == 3)
                WorldData.spriteBatch.DrawString(TextureManager.Instance.GetSpriteFont(MenuFont1), "Credits", new Vector2(nX, 250), Color.Yellow);
            else
                WorldData.spriteBatch.DrawString(TextureManager.Instance.GetSpriteFont(MenuFont1), "Credits", new Vector2(nX, 250), Color.White);
           
            if(option == 4)
                WorldData.spriteBatch.DrawString(TextureManager.Instance.GetSpriteFont(MenuFont1), "Exit", new Vector2(nX, 300), Color.Yellow);
           else
                WorldData.spriteBatch.DrawString(TextureManager.Instance.GetSpriteFont(MenuFont1), "Exit", new Vector2(nX, 300), Color.White);
               
        }
        override public void Enter()
        {
            option = 0;
            AudioManager.Instance.StopSFX("applause");

            AudioManager.Instance.PlaySong("Main Menu", true);

            WorldData.spriteBatch.GraphicsDevice.Reset();
            CInput.Instance.Clear();
         
        }
       override public void Exit()
        {

        }

    }
}
